package com.bnzj.cloud.business.core.persistence.repository;

import com.bnzj.cloud.business.core.persistence.entity.SysDictionary;
import com.bnzj.core.persistence.repository.BaseRepository;

import java.util.Optional;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * @author barry
 * @date 2019-09-27
 */
@Repository
public interface SysDictionaryRepository extends BaseRepository<SysDictionary, Long> {

    @Modifying
    @Query(value = "update bnz_sys_dictionary set  deleted = true where id = ?1", nativeQuery = true)
    void deletedById(Long id);

    @Query(value="SELECT a.* FROM	bnz_sys_dictionary a LEFT JOIN bnz_sys_dictionary_type b ON b.id = a.type_id"
    		+ "	WHERE b.code =?1 AND a.name=?2",nativeQuery = true)
    Optional<SysDictionary> findByTypeAndName(String typeCode,String name);
}
